Google Cloud Datalab provides functionality to easily use the Google Charting API to produce interactive, JavaScript and SVG-based charts from your data, whether your data was loaded from BigQuery, CSV files, or another source loaded into a vanilla Python list.
These charts can be produced through the %%chart
command.
In [1]:
%%chart --help
As you can see, a variety of chart types are supported.
In [2]:
%%chart line --help
The data to be charted is passed in as an argument.
Columns in data must be in a specific order according to the chart type. The --field argument, which takes a comma-separated list of field names, allows specifying the ordered set of columns to chart.
The body of the cell can include additional chart-specific options to pass to the chart.
In [3]:
%%bq query --name timeseries
SELECT timestamp, AVG(latency) AS latency FROM (
SELECT TIMESTAMP_TRUNC(timestamp, HOUR) AS timestamp, latency
FROM `cloud-datalab-samples.httplogs.logs_20140615`
WHERE endpoint = 'Popular'
)
GROUP BY timestamp
ORDER BY timestamp
In [4]:
%bq execute -q timeseries
Out[4]:
In [5]:
%%chart line --fields timestamp,latency --data timeseries
Out[5]:
Bar charts and column charts are similar to line charts.
In [6]:
%%bq query -n births
SELECT gestation_weeks AS weeks, weight_pounds AS weight
FROM `publicdata.samples.natality`
WHERE gestation_weeks < 99
LIMIT 1000
In [7]:
%%chart scatter --data births
title: Birth Weight vs Weeks
height: 400
width: 900
hAxis:
title: Weeks
vAxis:
title: Weight
legend: none
Out[7]:
In [8]:
%%bq query -n languages
SELECT repository_language AS language, COUNT(repository_language) as activity
FROM `publicdata.samples.github_timeline`
WHERE type = 'PushEvent'
AND repository_language != ''
GROUP BY language
ORDER BY activity DESC
LIMIT 10
In [9]:
%%chart pie --fields language,activity --data languages
title: Top 10 OSS Programming Languages
height: 400
width: 800
pieStartAngle: 20
slices:
0:
offset: .2
Out[9]:
In [10]:
%%bq query -n weather
SELECT max_temperature AS temperature,
SAFE_CAST(CONCAT(SAFE_CAST(year AS STRING), '-', SAFE_CAST(month AS STRING), '-', SAFE_CAST(day AS STRING)) AS TIMESTAMP) AS timestamp
FROM `publicdata.samples.gsod`
WHERE station_number = 727930 AND year >= 2000
ORDER BY year DESC, month DESC, day DESC
In [11]:
%%chart annotation --fields timestamp,temperature --data weather
Out[11]: